home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Demos / Extend 3.0 Demo / Demo Libraries / Demo Engineering Lib / Demo Engineering Lib.rsrc / MODL_15135_Comparator < prev    next >
Encoding:
Text File  |  1994-06-22  |  1.8 KB  |  67 lines

  1. // BD - 3/4/92 - added init of oldState
  2.  
  3. integer oldState;
  4.  
  5. on initsim
  6. {
  7. oldState = FALSE;
  8. }
  9.  
  10. on createBlock
  11. {
  12. hysteresis = 0.0;
  13. oldstate = FALSE;
  14. }
  15.  
  16. on simulate
  17. {
  18. if (oldState)
  19.     {
  20.     if (con2in > con1in+hysteresis)
  21.         oldState = FALSE;
  22.     }
  23. else
  24.     {
  25.     if (con1in > con2in+hysteresis)
  26.         oldState = TRUE;
  27.     }
  28.  
  29. if (inverting)
  30.     con3out = !oldState;
  31. else
  32.     con3Out = oldState;
  33.  
  34. ** sysGlobal2 is the file reference number for the DEBUG TRACE
  35. if( sysGlobal2 != 0.0 )    ** 0 is error, check for open file for TRACE
  36.     {
  37. // template for report:      |BLOCK NAME *****************|block number |BLOCK NUMBER*******
  38.     fileWrite(sysGlobal2,"Comparator                  block number "+(MyBlockNumber())+".  Current Time:"+currentTime+".","",True);
  39.     if(getBlockLabel(myBlockNumber()) != "")
  40.         fileWrite(sysGlobal2,"Block Label: "+getBlockLabel(myBlockNumber()),"",True);
  41.     fileWrite(sysGlobal2,"     Input+ = "+con1In,"",True);
  42.     fileWrite(sysGlobal2,"     Input- = "+con2In,"",True);
  43.     fileWrite(sysGlobal2,"     Output = "+con3out,"",True);
  44.     fileWrite(sysGlobal2," ","",True);
  45.     }
  46. }
  47.  
  48. on endSim
  49. {
  50. ** sysGlobal1 is the file reference number for the TEXT REPORT
  51. if( sysGlobal1 != 0.0 ) ** 0 is error, check for open file for REPORT
  52.     {
  53. // template for report:      |BLOCK NAME *****************|block number |BLOCK NUMBER*******
  54.     fileWrite(sysGlobal1,"Comparator                  block number "+(MyBlockNumber()),"",True);
  55.     if(getBlockLabel(myBlockNumber()) != "")
  56.         fileWrite(sysGlobal1,"Block Label: "+getBlockLabel(myBlockNumber()),"",True);
  57.     fileWrite(sysGlobal1,"     Hysteresis = "+hysteresis,"",True);
  58.     If (inverting)
  59.         fileWrite(sysGlobal1,"     Inverting mode","",True);
  60.     else
  61.         fileWrite(sysGlobal1,"     Non-inverting mode","",True);
  62.     if( comments != "" )
  63.         fileWrite(sysGlobal1,"     Comments = "+comments,"",True);        
  64.     fileWrite(sysGlobal1," ","",True);
  65.     }
  66. }
  67.